<?php

class Login extends CI_Controller {

    function index(){
        $this->load->view('login_form');
    }

    function validate_credentials(){
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();
        if($query){
                $data = $this->membership_model->userInfo($this->input->post('username'));
                $this->session->set_userdata($data);
                redirect('admin/main');
        }
        else{ // incorrect username or password
                //$this->lang->load('users', lang_title_from_URL($this));
                load_lang_file('users');
                $data['error_msg'] = $this->lang->line('login_incorrect');
                $this->load->view('login_form', $data);
        }
    }

    function logout(){
        $this->session->sess_destroy();
        $this->index();
    }

}